<?php
/**
 * Created by IntelliJ IDEA.
 * User: admin
 * Date: 2020/12/11
 * Time: 18:54
 */

namespace app\api\controller;


class Up extends Common
{

    public function upimg(){

        $this->checkSign(true);
        $file = isset($_FILES['file'])?$_FILES['file']:'';
        if(!$file){
            return json(["code"=>166,"error"=>["message"=>"请上传图片"]]);
        }
        $file = request()->file('file');
        // 移动到框架应用根目录/uploads/ 目录下
        $info = $file->validate(['size'=>2097152,'ext'=>'jpg,png,gif'])->move( './uploads');
        if($info){
            return package(0,'上传成功',"/uploads/".$info->getSaveName());
        }else{
            // 上传失败获取错误信息
            return package(10016,$file->getError());
        }
    }
}